<template>
    <a-date-picker
            :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
            :placeholder="placeholder"
            format="YYYY-MM-DD HH:mm:ss"
            @change="handleOk"
            :defaultValue="defaultValue? moment(defaultValue) : isToday? moment().startOf('day'):null"
    />
</template>


<script>
    import moment from 'moment';

    export default {
        name: "DatePacker",
        props: {
            placeholder: {
                modelValue: String,
                default: '选择时间'
            },
            defaultValue: {
                modelValue: String,
                default: false
            },
            isToday: {
                modelValue: Boolean,
                default: false
            }
        },
        methods: {
            moment,
            handleOk(value, dateString) {
                this.$emit("update:modelValue", dateString);
            }
        },
        mounted() {
            if (this.defaultValue){
                this.handleOk(null,this.defaultValue);
            }

            if (this.isToday){
                this.handleOk(null,moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'));
            }
        }
    }
</script>